local xuexiong = fk.CreateSkill {
  name = "lingling__xuexiong",
}

Fk:loadTranslationTable{
  ["lingling__xuexiong"] = "削雄",
  [":lingling__xuexiong"] = "出牌阶段限一次，你可以令一名你上回合未以此法选择的角色弃置三张牌（不足全弃，无牌不弃），其下回合开始时"..
  "和结束时各摸一张牌。",

  ["#lingling__xuexiong"] = "削雄：令一名角色弃三张牌，其下回合开始时和结束时各摸一张牌",
}

xuexiong:addEffect("active", {
  anim_type = "control",
  prompt = "#lingling__xuexiong",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(xuexiong.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    return #selected == 0 and not table.contains(player:getTableMark("lingling__xuexiong_record-turn"), to_select.id)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:addTableMark(player, "lingling__xuexiong_record", target.id)
    room:askToDiscard(target, {
      min_num = 3,
      max_num = 3,
      include_equip = true,
      skill_name = xuexiong.name,
      cancelable = false,
    })
    if target.dead then return end
    room:addPlayerMark(target, xuexiong.name, 1)
  end,
})

xuexiong:addEffect(fk.TurnStart, {
  anim_type = "drawcard",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("lingling__xuexiong-turn") > 0
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(player:getMark("lingling__xuexiong-turn"), xuexiong.name)
  end,

  can_refresh = function (self, event, target, player, data)
    return target == player and (player:getMark(xuexiong.name) > 0 or #player:getTableMark("lingling__xuexiong_record") > 0)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if player:getMark(xuexiong.name) > 0 then
      room:setPlayerMark(player, "lingling__xuexiong-turn", player:getMark(xuexiong.name))
      room:setPlayerMark(player, xuexiong.name, 0)
    end
    if #player:getTableMark("lingling__xuexiong_record") > 0 then
      room:setPlayerMark(player, "lingling__xuexiong_record-turn", player:getMark("lingling__xuexiong_record"))
      room:setPlayerMark(player, "lingling__xuexiong_record", 0)
    end
  end,
})

xuexiong:addEffect(fk.TurnEnd, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("lingling__xuexiong-turn") > 0
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(player:getMark("lingling__xuexiong-turn"), xuexiong.name)
  end,
})

return xuexiong
